/*
 * This subclass only adds a few responsibilities to the Application 
 * class. It loads the info and preferences panels on demand, 
 * and overrides sendEvent: to watch for control-mouseDown events
 * which it vectors off to the help object.
 *
 * Author: Julie Zelenski, NeXT Developer Support
 * You may freely copy, distribute and reuse the code in this example.  
 * NeXT disclaims any warranty of any kind, expressed or implied, as to 
 * its fitness for any particular use.
 */

#import <appkit/appkit.h>
#import "BusyBoxApp.h"
#import "Help.h"
#import <strings.h>
#import <libc.h>		// for chdir, getwd


@implementation BusyBoxApp

/* TARGET/ACTION METHODS */

- info:sender
/*
 * The info panel is a separate nib module and only loaded on demand.
 */
{
    if (!infoPanel) {
	if (![self loadNibSection:"InfoPanel.nib" owner:self withNames:NO]) {
	    NXLogError ("Could not load InfoPanel.nib");
	}
    }
    [infoPanel makeKeyAndOrderFront:self];
    return self;
}

- preferences:sender
/*
 * The preferences panel is a separate nib module and only loaded on demand.
 */
{
    if (!prefPanel) {
	if (![self loadNibSection:"PrefPanel.nib" owner:self withNames:NO]) {
	    NXLogError ("Could not load PrefPanel.nib");
	}
    }
    [prefPanel makeKeyAndOrderFront:self];
    return self;
}



- appDidInit:sender;
/* Upon starting, app asks Help object to bring up help panel and display the
 * general help information.
 */
{
    [helpObject generalHelp:self];
    return self;
}

- sendEvent:(NXEvent *)event;
/* I override sendEvent: so that I can snarf control-mouseDown events.
 * When the user holds Control key down and clicks on something, this
 * method will figure out which window received the click, finds the
 * view which is directly under the mouse down, and passes that information
 * to the help object who will display the appropriate help file.  If this
 * isn't a control-mouseDown event, I just call the super Application 
 * sendEvent: method to handle the event normally.
 */
 {    
    id window,view;

    if ((event->type == NX_LMOUSEDOWN) && (event->flags & NX_CONTROLMASK)) {
        window = [self findWindow:event->window];
	view = [[window contentView] hitTest:&event->location];
	if (view) [helpObject helpForView:view atPoint:&event->location];
	else [helpObject helpForWindow:window];
    }
    else [super sendEvent:event];
    return self;
}

@end
